package com.shuqing.config;

import com.shuqing.interceptor.ResourceInterceptor;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @program: ShuqingLibrary
 * @ClassName SpringMvcConfig
 * @description:
 * @author: Ats
 * @create: 2025-03-31 09:30
 * @Version 1.0
 */

@Configurable
@ComponentScan("com.shuqing.controller")
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    /**
     * 创建视图解析器，默认会去src/main/webapp/admin下寻找
     * @param registry
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/admin/", ".jsp");
    }

    /**
     * 将自定义登录权限拦截器添加到配置文件里
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ResourceInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**", "/js/**", "/img/**");
    }
}
